package com.wuzuqing.android.eightdiagrams.utils;


import android.util.Log;

import com.wuzuqing.android.eightdiagrams.dao.BaZhiHistory;
import com.wuzuqing.android.eightdiagrams.model.BaZiInfo;
import com.wuzuqing.android.eightdiagrams.model.CalculationTypeModel;
import com.wuzuqing.android.eightdiagrams.model.City;
import com.wuzuqing.android.eightdiagrams.model.CuiCaiDiLiFangWei;
import com.wuzuqing.android.eightdiagrams.model.DiZhiModel;
import com.wuzuqing.android.eightdiagrams.model.DizhiShierlunModel;
import com.wuzuqing.android.eightdiagrams.model.EightDagramsDetaiiModel;
import com.wuzuqing.android.eightdiagrams.model.EightDagramsInfoModel;
import com.wuzuqing.android.eightdiagrams.model.EightDagramsModel;
import com.wuzuqing.android.eightdiagrams.model.Fc3DOpenModel;
import com.wuzuqing.android.eightdiagrams.model.HeHuaModel;
import com.wuzuqing.android.eightdiagrams.model.LhcBean;
import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaItem;
import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaJuModel;
import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaModel;
import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaInfoModel;
import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaXingModel;
import com.wuzuqing.android.eightdiagrams.model.TermModel;
import com.wuzuqing.android.eightdiagrams.model.TianGanModel;
import com.wuzuqing.android.eightdiagrams.model.WenWangShenShuBiaoModel;
import com.wuzuqing.android.eightdiagrams.model.WuXingInfoModel;
import com.wuzuqing.android.eightdiagrams.task.IQiMenDunJiaTask;
import com.wuzuqing.android.eightdiagrams.task.QiMenDunJiaStep1Task;
import com.wuzuqing.android.eightdiagrams.task.QiMenDunJiaStep2Task;
import com.wuzuqing.android.eightdiagrams.task.QiMenDunJiaStep3Task;
import com.wuzuqing.android.eightdiagrams.task.QiMenDunJiaStep4Task;
import com.wuzuqing.android.eightdiagrams.task.QiMenDunJiaStep5Task;
import com.wuzuqing.android.eightdiagrams.task.QiMenDunJiaStep6Task;
import com.wuzuqing.android.eightdiagrams.task.QiMenDunJiaStep7Task;
import com.wuzuqing.android.eightdiagrams.term.ExactDate;
import com.wuzuqing.android.eightdiagrams.term.Lunar;
import com.wuzuqing.android.eightdiagrams.term.Solar;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * 作者：士元
 * 时间：2019/8/9 14:09
 * 邮箱：wuzuqing@linghit.com
 * 说明：
 */
public class DataUtils {
    private static List<EightDagramsModel> sEightDagramsModels = new ArrayList<>(8);
    private static List<TianGanModel> sTianGanModels = new ArrayList<>(10);
    private static List<DiZhiModel> sDiZhiModels = new ArrayList<>(12);
    private static List<EightDagramsDetaiiModel> sEightDagramsDetailModels = new ArrayList<>(64);
    private static Map<String, EightDagramsInfoModel> sEightDagramsInfoModels = new HashMap<>(64);
    private static Map<String, CalculationTypeModel> sEightDagramsTypes = new HashMap<>();
    private static Map<String, WenWangShenShuBiaoModel> mWenWangShenShuBiaos = new HashMap<>();
    private static Map<String, WuXingInfoModel> sWuxingInfos = new HashMap<>();
    private static Map<String, String> sWuxingShengKe = new HashMap<>();
    private static Map<String, List<City>> sCityInfos = new HashMap<>();
    private static Map<Integer, List<String>> sShiShenInfo = new HashMap<>();
    private static Map<String, String> sShiErYunInfo = new HashMap<>();
    private static Map<String, List<String>> sShiErYunInfo1 = new HashMap<>();
    private static Map<String, String> sLiuJiaKongWang = new HashMap<>();
    private static Map<String, String> sNaYinTu = new HashMap<>();
    private static Map<String, Integer> sLucyNumber = new HashMap<>();
    private static Map<String, TermModel> sTerm = new HashMap<>();
    private static Map<String, String> sHeHua = new HashMap<>();
    private static Map<String, String> sLiuYue = new HashMap<>();
    private static Map<String, HeHuaModel> sHeHuaMap = new HashMap<>();
    private static Map<String, DizhiShierlunModel> sDizhiSHierlunMap = new HashMap<>();
    private static Map<String, String> sKumahuaMap = new HashMap<>();
    private static Map<String, String> sCaiKuMap = new HashMap<>();
    // Map<String, String> readText
    private static Map<String, String> sFc3DOpenNumMap = new HashMap<>();
    private static Map<String, String> sTcp3OpenNumMap = new HashMap<>();
    private static List<String> sProvinceNames = new ArrayList<>();
    private static List<String> sLiuShiJiaZi = new ArrayList<>();
    private static Map<String, QiMenDunJiaJuModel> sQiMenDunJiaJu = new HashMap<>();
    private static Map<String, QiMenDunJiaXingModel> sQiMenDunJiaJiuXing = new HashMap<>();//
    private static Map<String, QiMenDunJiaInfoModel> sQiMenDunJiaBaShen = new HashMap<>();//
    private static Map<String, QiMenDunJiaInfoModel> sQiMenDunJiaBaMen = new HashMap<>();//
    private static Map<String, QiMenDunJiaInfoModel> sQiMenDunJiaBaMenLuoGong = new HashMap<>();//
    private static Map<String, QiMenDunJiaInfoModel> sQiMenDunJiaBaWangXiang = new HashMap<>();//
    private static Map<String, String> sQiMenDunJiaJiuXingWang = new HashMap<>();//
    private static Map<String, LhcBean> sXglhcMap = new HashMap<>();//
    private static String regex = "_";
    private static String line = "\\|";

    private static IInitHelper sInitHelper = new JavaInitHelper();

    private static Map<String, String> sGuPiaoMap = new HashMap<>();

    public static void setInputStream(IInitHelper stream) {
        sInitHelper = stream;
    }


    public static InputStream openFile(String name) {
        return sInitHelper.open(name);
    }

    public static void init() {
        try {
            String string = readString4(sInitHelper.open("eight_diagrams_base.txt"), regex);
            String[] split = string.split(regex);
            for (String s : split) {
                createEightDagrams(s.trim());
            }
            string = readString4(sInitHelper.open("eight_diagrams_info.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                createEightDagramsInfo(s.trim());
            }

            string = readString4(sInitHelper.open("tiangan_info.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                createTianGan(s.trim());
            }
            string = readString4(sInitHelper.open("dizhi_info.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                createDiZhi(s.trim());
            }


            string = readString4(sInitHelper.open("eight_diagrams_detail_1.txt"), "");
            split = string.split("\\*");
            for (String s : split) {
                createEightDagramsDetail1(s.trim());
            }
            string = readString4(sInitHelper.open("eight_diagrams_type.txt"), "");
            split = string.split("\\*");
            for (String s : split) {
                createEightDagramsType(s.trim());
            }
            string = readString4(sInitHelper.open("wenwangshenshubiao.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                createWenWangShenShuBiao(s.trim());
            }
            string = readString4(sInitHelper.open("wuxing_info.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                createWuXingInfo(s.trim());
            }
            string = readString4(sInitHelper.open("wuxing_shengke.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                createWuXingShengKe(s.trim());
            }
            string = readString4(sInitHelper.open("wuxing_extra.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleWuXingExtra(s.trim());
            }
            string = readString4(sInitHelper.open("shieryun.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleShiErYun(s.trim());
            }
            string = readString4(sInitHelper.open("liujia.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleLiuJiaKongWang(s.trim());
            }
            string = readString4(sInitHelper.open("nayintu.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleNaYinTu(s.trim());
            }
            string = readString4(sInitHelper.open("term1.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleTerm(s.trim());
            }
            string = readString4(sInitHelper.open("bzheihua.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleHeHua(s.trim());
            }
            string = readString4(sInitHelper.open("bzheihua1.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleHeHuaDetail(s.trim());
            }
            string = readString4(sInitHelper.open("dizhishierlun.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleDezhiShierlun(s.trim());
            }
            string = readString4(sInitHelper.open("kumahua.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleKumahua(s.trim());
            }
            string = readString4(sInitHelper.open("qimendunjiageju.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleQiMenDunJiaJu(s.trim());
            }
            string = readString4(sInitHelper.open("qimendunjiagexing.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleQiMenDunJiaXing(s.trim());
            }

            string = readString4(sInitHelper.open("qimendunjiagexingwang.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleQiMenDunJiaXingWang(s.trim());
            }
            string = readString4(sInitHelper.open("qimendunjiashen.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleQiMenDunJiaShen(s.trim());
            }
            string = readString4(sInitHelper.open("qimendunjiamen.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleQiMenDunJiaBaMen(s.trim());
            }
            string = readString4(sInitHelper.open("qimendunjiamenluogong.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleQiMenDunJiaBaMenLuoGong(s.trim());
            }
            string = readString4(sInitHelper.open("qimendunjiaWX.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                //
                handleQiMenDunJiaWx(s.trim());
            }

            string = readString4(sInitHelper.open("gupiao.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleGuPiao(s.trim());
            }

            string = readString4(sInitHelper.open("xglhc1.txt"), regex);
            split = string.split(regex);
            for (String s : split) {
                handleXglhx(s.trim());
            }
            initCity();
            initShiShen();
            sFc3DOpenNumMap = readFc3DNum();
            sTcp3OpenNumMap = readTcp3Num();
            print();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void handleQiMenDunJiaJu(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        sQiMenDunJiaJu.put(strings[0], new QiMenDunJiaJuModel(strings[0], strings[1], strings[2]));
    }

    private static void handleQiMenDunJiaShen(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        sQiMenDunJiaBaShen.put(strings[0], new QiMenDunJiaInfoModel(strings[0], strings[1],
                strings[2]));
    }

    private static void handleQiMenDunJiaBaMen(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        sQiMenDunJiaBaMen.put(strings[0], new QiMenDunJiaInfoModel(strings[0], strings[1],
                strings[2]));
    }

    private static void handleQiMenDunJiaBaMenLuoGong(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        sQiMenDunJiaBaMenLuoGong.put(strings[0], new QiMenDunJiaInfoModel(strings[0].substring(0, 2), strings[1],
                strings[2]));
    }

    private static void handleQiMenDunJiaWx(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        sQiMenDunJiaBaWangXiang.put(strings[0], new QiMenDunJiaInfoModel(strings[0], strings[1],
                ""));
    }

    private static void handleGuPiao(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        sGuPiaoMap.put(strings[0], strings[1]);
    }
    static Map<String,List<String>> aa = new HashMap<>();
    private static void handleXglhx(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        List<String> nums = new ArrayList<>();
        for (int i = 2; i < strings.length; i++) {
            nums.add(strings[i]);
        }
        LhcBean bean = new LhcBean();
        //2025084=星期二
        String year = strings[0].substring(0,4);
        List<String> list = aa.get(year);
        if (list==null){
            list = initYear(year);
            aa.put(year,list);
        }
        bean.setDate(strings[0]);
        bean.setNo(strings[1]);
        for (int i = nums.size() - 1; i >= 0; i--) {
            String num = nums.get(i);
            String[] split = num.split(",");
            LhcBean.NumBean numBean = new LhcBean.NumBean();
            numBean.setNum(Integer.parseInt(split[0]));
            numBean.setAnimal(list.get(numBean.getNum() - 1));
            bean.getList().add(numBean);
        }
        sXglhcMap.put(strings[0], bean);
    }
   private static final String[] Animals = new String[]{"鼠", "牛", "虎", "兔", "龙", "蛇",
            "马", "羊", "猴", "鸡", "狗", "猪"};
    private static List<String> initYear(String yearStr){
        List<String> result = new ArrayList<>();
        String animal = Animals[(Integer.parseInt(yearStr) - 4) % 12];
        result.add(animal);
        List<String> list = Arrays.asList(Animals);
        int index = list.indexOf(animal)+72;
        for (int i = 1;i<49;i++){
            int realIndex = (index-i)%12;
            result.add(Animals[realIndex]);
        }
        return result;
    }

    private static void handleQiMenDunJiaXing(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        sQiMenDunJiaJiuXing.put(strings[0], new QiMenDunJiaXingModel
                (strings[0], strings[1], strings[2], strings[3], strings[4], strings[5],
                        strings[6], strings[7],
                        strings[8]
                        , strings[9]
                ));
    }

    static String[] jiuXing = new String[]{
            "天蓬",
            "天任",
            "天冲",
            "天辅",
            "天禽",
            "天英",
            "天芮",
            "天柱",
            "天心"
    };

    private static void handleQiMenDunJiaXingWang(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        //寅|旺|囚|相|相|囚|废|囚|休|休
        for (int k = 1; k < strings.length; k++) {
            for (int i = 0; i < jiuXing.length; i++) {
                String xing = jiuXing[i];
                sQiMenDunJiaJiuXingWang.put(xing + strings[0], strings[i + 1]);
            }
        }
    }

    public static boolean isEmpty(CharSequence str) {
        return str == null || str.length() == 0;
    }

    public static boolean equals(CharSequence a, CharSequence b) {
        if (a == b) return true;
        int length;
        if (a != null && b != null && (length = a.length()) == b.length()) {
            if (a instanceof String && b instanceof String) {
                return a.equals(b);
            } else {
                for (int i = 0; i < length; i++) {
                    if (a.charAt(i) != b.charAt(i)) return false;
                }
                return true;
            }
        }
        return false;
    }

    private static void handleKumahua(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        if (strings[0].equals("1")) {
            sKumahuaMap.put(strings[1], strings[2]);
        } else if (strings[0].equals("2")) {
            sCaiKuMap.put(strings[1], strings[2]);
        }
    }

    private static void handleDezhiShierlun(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        DizhiShierlunModel model = new DizhiShierlunModel(strings[0], strings[1], strings[2]);
        sDizhiSHierlunMap.put(model.getZhi(), model);
    }

    private static void handleHeHuaDetail(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        HeHuaModel model = new HeHuaModel(Integer.parseInt(strings[0]),
                strings[1],
                strings[2],
                strings[3],
                strings[4]
        );
        String key = strings[1];
//        if (key.length() == 2) {
//            sHeHuaMap.put(new StringBuilder(key).reverse().toString(), model);
//        }
        sHeHuaMap.put(key, model);
    }

    private static void handleHeHua(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        sHeHua.put(strings[1], strings[0]);
        sHeHua.put(strings[0], strings[1]);
    }

    private static void handleTerm(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        sTerm.put(strings[1].substring(0, 10), new TermModel(strings[0], strings[1]));
    }

    private static void handleLiuJiaKongWang(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        for (int i = 1; i <= strings.length - 1; i++) {
            sLiuJiaKongWang.put(strings[i], strings[0]);
        }
    }

    private static void handleNaYinTu(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        for (int i = 0; i < strings.length; i++) {
            //甲子、乙丑-海中金|丙寅、丁卯-炉中火
            String[] arr = strings[i].split("-");
            String[] gz = arr[0].split("、");
            sNaYinTu.put(gz[0], arr[1]);
            sNaYinTu.put(gz[1], arr[1]);
        }
    }

    private static void handleShiErYun(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        String g = strings[0];
        List<String> zhi = new ArrayList<>();
        for (int i = 1; i < strings.length; i++) {
            String z = strings[i];
            sShiErYunInfo.put(g + z, Yun[i - 1]);
            zhi.add(z);
        }
        sShiErYunInfo1.put(g, zhi);
    }

    static String[] Yun = new String[]{
            "长生", "沐浴", "冠带", "临高", "帝旺", "衰", "病", "死", "幕", "绝", "胎", "养"
    };
    static String[] Gan = new String[]{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
    public static String[] Zhi = new String[]{
            "子",    // 23-01
            "丑",    //01-03
            "寅",    //03-05
            "卯",    //05-07
            "辰",    //07-09
            "巳",    //09-11
            "午",    //11-13
            "未",    //13-15
            "申",    //15-17
            "酉",    //17-19
            "戌",    //19-21
            "亥"     //21-23
    };

    private static void initShiShen() {
        //0 =生我 1=比我 2=克我 3=我生 4=我克
        //比肩、劫财、食神、伤官、偏财、正财、七杀、正官、偏印、正印
        //1、生我者为枭印。同性为偏印，也叫枭神，简称枭;异性为正印，简称印。比如日干为甲木，壬、子水为偏印，癸亥则为正印。
        //2、同我者为比劫。同性为比肩，简称比;异性为劫财，简称劫。比如日干为甲，甲、寅为比肩，乙卯为劫财。
        //3、我生者为食伤。同性为食神，简称食;异性为伤官，简称伤。比如日干为甲，丙午为食神，丁巳为伤官。
        //4、我克者为才财。同性为偏财，简称财;异性为正财，简称才。比如日干为甲，戊、辰、戌土就是偏财，己、丑，未土就是正财。
        //5、克我者为杀官。同性为偏官，或者七杀，简称杀;异性为正官，简称官。比如日干为甲木，庚申为七杀，辛酉为正官。
        sShiShenInfo.put(0, Arrays.asList("偏印", "正印"));
        sShiShenInfo.put(1, Arrays.asList("比肩", "劫财"));
        sShiShenInfo.put(2, Arrays.asList("七杀", "正官"));
        sShiShenInfo.put(3, Arrays.asList("食神", "伤官"));
        sShiShenInfo.put(4, Arrays.asList("偏财", "正财"));
        sLucyNumber.put("辰", 4);
        sLucyNumber.put("巳", 4);
        sLucyNumber.put("卯", 3);
        sLucyNumber.put("寅", 8);
        sLucyNumber.put("丑", 8);
        sLucyNumber.put("子", 1);
        sLucyNumber.put("亥", 6);
        sLucyNumber.put("戌", 6);
        sLucyNumber.put("酉", 7);
        sLucyNumber.put("申", 2);
        sLucyNumber.put("未", 2);
        sLucyNumber.put("午", 9);

        for (int i = 0; i < 120; i++) {
            sLiuShiJiaZi.add(Gan[i % 10] + Zhi[i % 12]);
        }
        //  //甲己=丙  1,6=3
        //        //乙庚=戊  2,7=5
        //        //丙辛=庚  3,8=7
        //        //丁壬=壬	4,9=9
        //        //戊癸=甲	5,10=1
        sLiuYue.put("甲", "丙");
        sLiuYue.put("己", "丙");
        sLiuYue.put("乙", "戊");
        sLiuYue.put("庚", "戊");
        sLiuYue.put("丙", "庚");
        sLiuYue.put("辛", "庚");
        sLiuYue.put("丁", "壬");
        sLiuYue.put("壬", "壬");
        sLiuYue.put("戊", "甲");
        sLiuYue.put("癸", "甲");
    }

    private static void createDiZhi(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        DiZhiModel model = new DiZhiModel();
        model.setName(strings[0]);
        model.setWuXing(strings[2]);
        model.setId(Integer.parseInt(strings[1]));
        model.setMonth(Integer.parseInt(strings[3]));
        model.setShiChen(strings[4]);
        model.setWuXingAttr(strings[5]);
        model.setAnimal(strings[6]);
        model.setFangWei(strings[7]);
        model.setColor(strings[8]);
        model.setCangGan(strings[9]);
        sDiZhiModels.add(model);
    }

    private static void createTianGan(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        TianGanModel model = new TianGanModel();
        model.setName(strings[0]);
        model.setWuXing(strings[2]);
        model.setId(Integer.parseInt(strings[1]));
        model.setWuXingAttr(strings[3]);
        model.setParts(strings[4]);
        model.setYuYi(strings[5]);
        sTianGanModels.add(model);
    }

    private static void createWuXingInfo(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        WuXingInfoModel model = new WuXingInfoModel();
        model.setId(Integer.parseInt(strings[0]));
        model.setName(strings[1]);
        model.setFangwei(strings[2]);
        model.setWuchang(strings[3]);
        model.setWujie(strings[4]);
        model.setWuzang(strings[5]);
        model.setWudu(strings[6]);
        model.setColor(strings[7]);
        model.setTexing(strings[8]);
        model.setXing(strings[9]);
        sWuxingInfos.put(model.getName(), model);
    }

    private static void handleWuXingExtra(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        WuXingInfoModel model = null;
        for (int i = 0; i < strings.length; i++) {
            if (i == 0) {
                model = sWuxingInfos.get(strings[i]);
            } else {
                if (model != null) {
                    model.getShengKe().add(strings[i]);
                }
            }
        }
    }

    private static void createWuXingShengKe(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        if (strings.length >= 2) {
            sWuxingShengKe.put(strings[0].replaceAll("\uFEFF", ""), strings[1].trim());
        }
    }

    private static void createWenWangShenShuBiao(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        if (strings.length == 2) {
            WenWangShenShuBiaoModel calculationTypeModel = new WenWangShenShuBiaoModel();
            calculationTypeModel.setNumber(strings[1]);
            calculationTypeModel.setContent(strings[0]);
            mWenWangShenShuBiaos.put(calculationTypeModel.getNumber(), calculationTypeModel);
        }
    }

    public static WenWangShenShuBiaoModel getWenWangShenShu(int bai, int shi, int gei) {
        return mWenWangShenShuBiaos.get(String.format("%d%d%d", bai, shi, gei));
    }

    private static void createEightDagramsType(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] strings = s.split(line);
        if (strings.length == 2) {
            CalculationTypeModel calculationTypeModel = new CalculationTypeModel();
            calculationTypeModel.setId(strings[1]);
            calculationTypeModel.setName(strings[0]);
            sEightDagramsTypes.put(calculationTypeModel.getNumber(), calculationTypeModel);
        }
    }

    private static void createEightDagramsDetail1(String s) {
        if (isEmpty(s)) {
            return;
        }
        String[] split = s.split(line);
        if (split.length < 3) {
            return;
        }
        EightDagramsDetaiiModel model = new EightDagramsDetaiiModel();
        model.setEightYun(split[0]);
        model.setEightDiagramsId(Integer.parseInt(split[1]));
        model.setOriginalText(split[2]);
        model.setDownYao(split[3]);
        model.setYaoTwo(split[4]);
        model.setYaoThree(split[5]);
        model.setYaoFour(split[6]);
        model.setYaoFive(split[7]);
        model.setUpYao(split[8]);
        model.setYongYao(split[9]);
        model.setElephant(split[10]);
        model.setHexagram(split[11]);
        model.setContent(split[12]);
        sEightDagramsDetailModels.add(model);
    }

    public static EightDagramsModel getEightDagrams(int index) {
        if (index == 8) {
            return sEightDagramsModels.get(7);
        }
        return sEightDagramsModels.get((index % 8) - 1);
    }

    public static EightDagramsDetaiiModel getDetail(int index) {
        return sEightDagramsDetailModels.get(index - 1);
    }

    public static EightDagramsModel getEightDagrams(String yaoFlag) {
        for (EightDagramsModel model : sEightDagramsModels) {
            if (equals(yaoFlag, model.getYaoFlag())) {
                return model;
            }
        }
        return sEightDagramsModels.get(0);
    }

    public static EightDagramsInfoModel getEightDagramsInfo(String title, int up, int down) {
        EightDagramsInfoModel infoModel =
                sEightDagramsInfoModels.get(getInfoKey(up, down)).cloneSelf();
        infoModel.setTitle(title);
        return infoModel;
    }

    public static EightDagramsInfoModel getEightDagramsInfo(EightDagramsModel up,
                                                            EightDagramsModel down) {
        return getEightDagramsInfo("", up.getEightDiagramsId(), down.getEightDiagramsId());
    }

    public static EightDagramsInfoModel getEightDagramsInfo(String title, EightDagramsModel up,
                                                            EightDagramsModel down) {
        return getEightDagramsInfo(title, up.getEightDiagramsId(), down.getEightDiagramsId());
    }

    private static void print() {
//       sInitHelper.d(sEightDagramsModels.toString());
//       sInitHelper.d(sEightDagramsInfoModels.toString());
//        sInitHelper.d("天干"+ sTianGanModels.toString());
//        sInitHelper.d(sDiZhiModels.toString());
//        sInitHelper.d("五行"+ sWuxingInfos.toString());
//        sInitHelper.d(sWuxingShengKe.toString());
//        sInitHelper.d(sLiuJiaKongWang.toString());
//        sInitHelper.d(sShiShenInfo.toString());
//        sInitHelper.d(sNaYinTu.toString());
//        sInitHelper.d(sShiErYunInfo.toString());
        String[] ganList = new String[]{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
        StringBuilder sb = new StringBuilder();
        StringBuilder sb1 = new StringBuilder();
        sb1.append("干\t");
        for (String g : ganList) {
            sb1.append(g).append("\t");
        }
        sb1.append("\n");
        for (String riGan : ganList) {
            TianGanModel riTianGan = DataUtils.getTianGan(riGan);
            WuXingInfoModel xingInfoModel = DataUtils.getWuXingInfo(riTianGan.getWuXing());
            sb1.append(riGan).append("\t");
            for (String gan : ganList) {
                TianGanModel tg = DataUtils.getTianGan(gan);
                for (int i = 0; i < xingInfoModel.getShengKe().size(); i++) {
                    String wx = xingInfoModel.getShengKe().get(i);
                    if (Objects.equals(wx, tg.getWuXing())) {
                        String shiShen = getShiShen(i, riTianGan.getId(), tg.getId());
                        sb.append(riGan).append(gan).append("|").append(shiShen).append("\n");
                        sb1.append(shiShen).append("\t");
                        break;
                    }
                }
            }
            sb1.append("\n");
        }
//        sInitHelper.d(sb.toString());
//        sInitHelper.d(sTerm.toString());
        //  val ganList = arrayOf("甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸")
        //        var sb = StringBuilder()
        //        var sb1 = StringBuilder()
        //        ganList.forEach { riGan ->
        //            val riTianGan = DataUtils.getTianGan(riGan)
        //            sInitHelper.d(riTianGan.toString())
        //
        //            val riGanWuXingInfo = DataUtils.getWuXingInfo(riTianGan.wuXing) ?:
        //            return@forEach
        //            sInitHelper.d(riGanWuXingInfo.toString())
        ////            ganList.forEach { gan ->
        ////                val tianGan = DataUtils.getTianGan(gan)
        ////                riGanWuXingInfo?.shengKe?.forEachIndexed { index, s ->
        ////                    if (s == tianGan.wuXing) {
        ////                        val shiShen = DataUtils.getShiShen(index, riTianGan.id,
        // tianGan.id)
        ////                        sb.append(riGan).append(gan).append("|")
        ////                        sb1.append(riGan).append(gan).append("|").append(shiShen)
        // .append("\n")
        ////                    }
        ////                }
        ////            }
        //            sb.append("\n")
        //        }
//        for (String s : sQiMenDunJiaJiuXingWang.keySet()) {
//            LogUtils.d("啊啊->" + s + "=>" + sQiMenDunJiaJiuXingWang.get(s));
//        }
    }

    private static void createEightDagrams(String s) {
        if (isEmpty(s)) {
            return;
        }
        EightDagramsModel model = new EightDagramsModel();
        String[] split = s.split(line);
        model.setEightDiagramsId(Integer.parseInt(split[1].trim()));
        model.setEightDiagramsName(split[0]);
        model.setEightDiagramsAlias(split[2]);
        model.setYaoFlag(split[3]);
        model.setXianTianFangWei(split[4]);
        model.setHouTianFangWei(split[5]);
        model.setWuXing(split[6]);
        model.setWuXingSheng(split[7]);
        model.setWuXingKe(split[8]);
        model.setWangShuai(split[9]);
        model.setYinYang(split[10]);
        model.setZiNv(split[11]);
        sEightDagramsModels.add(model);
    }

    private static void createEightDagramsInfo(String s) {
        if (isEmpty(s)) {
            return;
        }
        EightDagramsInfoModel model = new EightDagramsInfoModel();
        String[] split = s.split(line);
        model.setEightDiagramsId(Integer.parseInt(split[1].trim()));
        model.setEightDiagramsName(split[0]);
        model.setUpperEightDiagrams(Integer.parseInt(split[2]));
        model.setDownEightDiagrams(Integer.parseInt(split[3]));
        sEightDagramsInfoModels.put(getInfoKey(model.getUpperEightDiagrams(),
                model.getDownEightDiagrams()), model);
    }

    private static String getInfoKey(int up, int down) {
        return String.format(Locale.getDefault(), "%d-%d", up, down);
    }

    /* 按行读对于要处理的格式化数据是一种读取的好方式 */
    private static String readString4(InputStream stream, String regex) throws IOException {
        int len = 0;
        StringBuffer str = new StringBuffer();
        try {
            InputStreamReader isr = new InputStreamReader(stream);
            BufferedReader in = new BufferedReader(isr);
            String line = null;
            boolean isFirst = true;
            while ((line = in.readLine()) != null) {
                if (isFirst) {
                    line = line.replaceAll("\uFEFF", "");
                    isFirst = false;
                }
                if (len != 0) // 处理换行符的问题
                {
                    str.append(regex).append(line);
                } else {
                    str.append(line);
                }
                len++;
            }
            in.close();
            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str.toString();
    }

    public static List<EightDagramsModel> getEightDagramsModels() {
        return sEightDagramsModels;
    }

    public static CalculationTypeModel getCalculationType(String type) {
        return sEightDagramsTypes.get(type);
    }

    public static List<CalculationTypeModel> getTypeList() {
        Set<String> keySet = sEightDagramsTypes.keySet();
        List<CalculationTypeModel> result = new ArrayList<>();
        for (String s : keySet) {
            result.add(sEightDagramsTypes.get(s));
        }
        Collections.sort(result, new Comparator<CalculationTypeModel>() {
            @Override
            public int compare(CalculationTypeModel o1, CalculationTypeModel o2) {
                return o1.getNumber().compareTo(o2.getNumber());
            }
        });
        return result;
    }

    public static String getWuXing(String tiWx, String yongWx) {
        String tsy = tiWx + "生" + yongWx;
        String a;
        if (sWuxingShengKe.containsKey(tsy)) {
            a = "体生用-" + tsy + " 小凶(30以下) 事难成;";
            return a;
        }
        String yst = yongWx + "生" + tiWx;
        if (sWuxingShengKe.containsKey(yst)) {
            a = "用生体-" + yst + " 大吉(90%) 事必成;";
            return a;
        }
        String tky = tiWx + "克" + yongWx;
        if (sWuxingShengKe.containsKey(tky)) {
            a = "体克用-" + tky + " 中吉(40-60%) 事可成;";
            return a;
        }
        String ykt = yongWx + "克" + tiWx;
        if (sWuxingShengKe.containsKey(ykt)) {
            a = "用克体-" + ykt + " 大凶(10以下) 事不成;";
            return a;
        }
        return "体用比合 次吉(70%) 事易成;";
    }

    public static List<String> getProvinceNames() {
        return sProvinceNames;
    }

    public static List<City> getCity(String province) {
        return sCityInfos.get(province);
    }

    public static void initCity() {
        if (!sCityInfos.isEmpty()) {
            return;
        }
        Set<String> set = new TreeSet<>();
        try {
            String string = readString4(sInitHelper.open("city.txt"), regex);
            String[] split = string.split(regex);
            int index = 0;
            String lastCity = "";
            for (String s : split) {
                String[] arr = s.split(line);
                String city = arr[0];
                if (!lastCity.equals(city)) {
                    index++;
                    lastCity = city;
                }
                List<City> cityList = sCityInfos.computeIfAbsent(city, k -> new ArrayList<>());
                cityList.add(new City(index, city, arr[1]));
                set.add(city);
            }
            sProvinceNames.addAll(set);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String[] getGanZhi(String text) {
        String[] result = new String[4];
        String ganText = text.charAt(0) + "";
        String zhiText = text.charAt(1) + "";
        result[0] = ganText;
        result[2] = zhiText;
        for (TianGanModel model : sTianGanModels) {
            if (ganText.equals(model.getName())) {
                result[1] = model.getWuXing();
                break;
            }
        }
        for (DiZhiModel model : sDiZhiModels) {
            if (zhiText.equals(model.getName())) {
                result[3] = model.getWuXing();
                break;
            }
        }
        return result;
    }

    public static WuXingInfoModel getWuXingInfo(String wx) {
        return sWuxingInfos.get(wx);
    }

    public static WuXingInfoModel getWuXing(BaZiInfo.BaseInfo info) {
        String riGan = info.getWuXing() + "";
        return sWuxingInfos.get(riGan);
    }


    public static boolean checkLikeWuXing(String wx, BaZiInfo.BaseInfo... infos) {
        return checkLikeWuXing(wx, Arrays.asList(infos));
    }

    public static boolean checkLikeWuXing(String wx, List<BaZiInfo.BaseInfo> infos) {
        for (BaZiInfo.BaseInfo info : infos) {
            if (Objects.equals(wx, info.getWuXing())) {
                return true;
            }
        }
        return false;
    }

    public static void put(Map<String, List<String>> map, List<String> values, String... keys) {
        for (String key : keys) {
            map.put(key, values);
        }

    }

    public static String getYiMa(String shiZhi) {
        switch (shiZhi) {
            case "申":
            case "子":
            case "辰":
                return "寅"; //申子辰时马星在寅位，
            case "寅":
            case "午":
            case "戌":
                return "申"; //寅午戌时马星在申位，
            case "亥":
            case "卯":
            case "未":
                return "巳"; //亥卯未时马星在已位，
            case "巳":
            case "酉":
            case "丑":
                return "亥"; //巳酉丑时马星在亥位。
        }
        return "";
    }

    public static List<Fc3DOpenModel> getOpenDate(String ju) {
        ArrayList<String> list = new ArrayList<>(sFc3DOpenNumMap.keySet());
        list.sort(Comparator.reverseOrder());
        List<Fc3DOpenModel> result = new ArrayList<>();
        int count = 0;
        for (String s : list) {
            Fc3DOpenModel openModel = new Fc3DOpenModel(s, getFc3DOpenDate(s), null, null, null, null);
            if (count < 5) {
                getFc3DOpenGan(openModel, ju);
            }
            count++;
            result.add(openModel);
        }
        return result;
    }

    private static int sHour = 13;
    private static int sMinute = 22;

    public static void saveHHmmss(int hour, int minute) {
        sHour = hour;
        sMinute = minute;
    }

    public enum CoinType {
        CONG_QIANG("从强", 20),
        QIANG("强", 72),
        PIAN_QIANG("偏强", 60),
        JUNHENG("均衡", 50),
        PIAN_RUO("偏弱", 40),
        RUO("弱", 24),
        CONG_RUO("从弱", 80);
        private String text;
        private int coin;

        CoinType(String text, int coin) {
            this.text = text;
            this.coin = coin;
        }

        public String getText() {
            return text;
        }

        public int getCoin() {
            return coin;
        }
    }

    public static CoinType measureCoin(BaZiInfo info) {
        //得令
        boolean dl = false;
        //得地
        boolean dd = false;
        //得势
        boolean ds = false;
        int zhuCount = 0;
        WuXingInfoModel model = getWuXing(info.getRiGanInfo());
        Map<String, List<String>> aa = new HashMap<>();
        put(aa, Arrays.asList("寅", "卯", "辰", "亥", "未"), "甲", "乙");
        put(aa, Arrays.asList("巳", "午", "未", "寅", "戌"), "丙", "丁");
        put(aa, Arrays.asList("辰", "戌", "丑", "未", "巳", "午", "寅"), "戊", "己");
        put(aa, Arrays.asList("申", "酉", "戌", "巳", "丑"), "庚", "辛");
        put(aa, Arrays.asList("亥", "子", "丑", "申", "辰"), "壬", "癸");
        Set<String> set = new HashSet<>(aa.get(info.getRiGanInfo().getName()));
        List<String> dzList = new ArrayList<>();
        dzList.add(info.getNianZhiInfo().getName());
        dzList.add(info.getYueZhiInfo().getName());
        dzList.add(info.getRiZhiInfo().getName());
        dzList.add(info.getShiZhiInfo().getName());

        List<String> wxList = new ArrayList<>();
        wxList.add(info.getNianGanInfo().getWuXing());
        wxList.add(info.getYueGanInfo().getWuXing());
        wxList.add(info.getShiGanInfo().getWuXing());
        wxList.add(info.getNianZhiInfo().getWuXing());
        wxList.add(info.getYueZhiInfo().getWuXing());
        wxList.add(info.getRiZhiInfo().getWuXing());
        wxList.add(info.getShiZhiInfo().getWuXing());


        int count = 0;
        for (String dz : dzList) {
            if (set.contains(dz)) {
                count++;
            }
        }
        dd = count > 0;
        List<String> shengKe = model.getShengKe();
        for (int i = 0; i < 2; i++) {
            if (checkLikeWuXing(shengKe.get(i), info.getYueZhiInfo())) {
                dl = true;
            }
            //检查天干
            if (checkLikeWuXing(shengKe.get(i), info.getNianGanInfo(), info.getYueGanInfo(),
                    info.getShiGanInfo())) {
                ds = true;
            }
        }
        Set<String> zhuSet = new HashSet<>(Arrays.asList(shengKe.get(0), shengKe.get(1)));
        for (String wz : wxList) {
            if (zhuSet.contains(wz)) {
                zhuCount++;
            }
        }
        //从强
        //除了日元以外了 七个字都是生助日元的为从强。
        //从强(日元强到极点反而变弱）
        //强
        //得令+得地＋得势=强
        //偏强
        //得令+得地＋不得势=偏强
        //得令＋不得地+得势=偏强
        //均衡
        //不得令＋得地+得势=均衡
        //得令＋不得地＋不得势=均衡
        //偏弱
        //不得令+不得地+得势
        //不得令+得地+不得势
        //弱
        //不得令＋不得地＋不得势=弱
        //从弱
        //除了日元以外 7个字都是克泄耗日元的
        //从弱(日元弱到极点反而变强了）
        if (zhuCount == 0) {
            //从弱,变得强
            return CoinType.CONG_RUO;
        } else if (zhuCount == 7) {
            //从强,变弱
            return CoinType.CONG_QIANG;
        } else if (dl && dd && ds) {
            //强
            return CoinType.QIANG;
        } else if (dl && dd || dl && ds) {
            //偏强
            return CoinType.PIAN_QIANG;
        } else if (dl || (dd && ds)) {
            //均衡
            return CoinType.JUNHENG;
        } else if (dd || ds) {
            //偏弱
            return CoinType.PIAN_RUO;
        } else {
            //弱
            return CoinType.RUO;
        }
    }

    public static int measureCoin(String[] nGZArr, String[] mGZArr,
                                  String[] dGZArr, String[] hGZArr) {
        String zhu = dGZArr[1];

        WuXingInfoModel model = sWuxingInfos.get(zhu);
        // 0 =生我 1=比我 2=克我 3=我生 4=我克
        int value = 0;
        if (model == null) {
            sInitHelper.d("measureCoin" + zhu + " info:" + sWuxingInfos);
            return value;
        }
        List<String> shengKe = model.getShengKe();
        for (int i = 0; i < 2; i++) {
            if (nGZArr[1].equals(shengKe.get(i))) {
                value += 8;
            }
            if (nGZArr[3].equals(shengKe.get(i))) {
                value += 4;
            }
            if (mGZArr[1].equals(shengKe.get(i))) {
                value += 12;
            }
            if (mGZArr[3].equals(shengKe.get(i))) {
                value += 40;
            }
            if (dGZArr[3].equals(shengKe.get(i))) {
                value += 12;
            }
            if (hGZArr[1].equals(shengKe.get(i))) {
                value += 12;
            }
            if (hGZArr[3].equals(shengKe.get(i))) {
                value += 12;
            }
        }
        return value;
    }

    public static String getXiYongShen(String riGan, int coin) {
        WuXingInfoModel model = sWuxingInfos.get(riGan);
        if (model == null) {
            return "";
        }
        List<String> shengKe = model.getShengKe();
        if (shengKe.size() != 5) {
            return "";
        }
        if (coin > 50) {
            return shengKe.get(2) + "," + shengKe.get(3) + "," + shengKe.get(4);
        }
        return shengKe.get(0) + "," + shengKe.get(1);
    }

    public static TianGanModel getTianGan(String name) {
        for (TianGanModel model : sTianGanModels) {
            if (model.getName().equals(name)) {
                return model;
            }
        }
        return new TianGanModel();
    }

    public static DiZhiModel getDiZhiInfo(String name) {
        for (DiZhiModel model : sDiZhiModels) {
            if (model.getName().equals(name)) {
                return model;
            }
        }
        return null;
    }

    public static String getShiShen(int index, boolean isSame) {
        List<String> list = sShiShenInfo.get(index);
        if (list == null || list.size() < 2) {
            return "未知";
        }
        return list.get(isSame ? 0 : 1);
    }

    public static String getShiShen(int index, int id1, int id2) {
        return getShiShen(index, (id1 % 2) == (id2 % 2));
    }

    public static String getShiErShen(String s) {
        return sShiErYunInfo.get(s);
    }

    public static List<String> getShiErShen1(String s) {
        sInitHelper.d("getShiErShen1:" + s + "," + sShiErYunInfo1.containsKey(s));
        return sShiErYunInfo1.get(s);
    }

    public static int getLucyNum(String zhi) {
        return sLucyNumber.get(zhi);
    }

    public static String getLiuJiaKongWang(String gan, String zhi) {
        return sLiuJiaKongWang.get(gan + zhi);
    }

    public static String getLiuJiaKongWang(String ganZhi) {
        return sLiuJiaKongWang.get(ganZhi);
    }

    public static String getNaYinTu(String gan, String zhi) {
        return sNaYinTu.get(gan + zhi);
    }

    public static String getNaYinTu(String gz) {
        return sNaYinTu.get(gz);
    }

    public static String getType(boolean boy, boolean yy) {
        if (boy) {
            return yy ? "阳男" : "阴男";
        }
        return yy ? "阳女" : "阴女";
    }

    public static boolean getType(String type) {
        return "阳男".equals(type) || "阴女".equals(type);
    }


    public static TermModel getTeamModel(String key) {
        return sTerm.get(key);
    }

    public static String getHeHuaZhi(String key) {
        return sHeHua.get(key);
    }

    public static List<String> getDaYun(String riGanZhi, boolean isXun) {
        List<String> list = new ArrayList<>();
        if (isXun) {
            int index = sLiuShiJiaZi.indexOf(riGanZhi);
            list.addAll(sLiuShiJiaZi.subList(index + 1, index + 9));
        } else {
            int index = sLiuShiJiaZi.lastIndexOf(riGanZhi);
            for (int i = 1; i <= 8; i++) {
                list.add(sLiuShiJiaZi.get(index - i));
            }
        }
        return list;
    }

    public static int getLiuYueFirst(String ganzhi) {
        //流年的太岁（即流年地支） 所在宫起正月，逆数到出生月宫上
        //甲己=丙  1,6=3
        //乙庚=戊  2,7=5
        //丙辛=庚  3,8=7
        //丁壬=壬	4,9=9
        //戊癸=甲	5,10=1

        String ganStr = ganzhi.substring(0, 1);
        ganStr = sLiuYue.get(ganStr);
        TianGanModel tianGan = getTianGan(ganStr);
        return tianGan.getId();
    }


    public static long[] getLiuRiRange(String year, String jieQi) {
        List<TermModel> termModels = new ArrayList<>();
        int yearInt = Integer.parseInt(year);
        String nextYear = (yearInt + 1) + "";
        for (String key : sTerm.keySet()) {
            if (key.startsWith(year) || key.startsWith(nextYear)) {
                termModels.add(sTerm.get(key));
            }
        }
        termModels.sort(new Comparator<TermModel>() {
            @Override
            public int compare(TermModel o1, TermModel o2) {
                return o1.getTime().compareTo(o2.getTime());
            }
        });

        int findIndex = 0;
        for (int i = 0; i < termModels.size(); i++) {
            TermModel termModel = termModels.get(i);
            if (termModel.getName().equals("立春")) {
                findIndex = i;
                break;
            }
        }
        termModels = termModels.subList(findIndex, termModels.size());

        for (int i = 0; i < termModels.size(); i++) {
            TermModel termModel = termModels.get(i);
            if (termModel.getName().equals(jieQi)) {
                findIndex = i;
                break;
            }
        }
        String startTime = termModels.get(findIndex).getTime();
        String endTime = termModels.get(findIndex + 2).getTime();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date dateStart = sf.parse(startTime);
            Date dateEnd = sf.parse(endTime);
            return new long[]{dateStart.getTime(), dateEnd.getTime() - (86400 * 1000)};
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return new long[]{0, 0};
    }


    private static void appendGanZhi(List<String> list, BaZiInfo.BaseInfo info) {
        if (info != null) {
            list.add(info.getName());
        }
    }

    public static List<HeHuaModel> getHeHuaGan(BaZiInfo info, boolean uedDyLn) {
        ArrayList<String> gan = new ArrayList<>();
        if (uedDyLn) {
            appendGanZhi(gan, info.getDaYunGanInfo());
            appendGanZhi(gan, info.getLiuNianGanInfo());
            appendGanZhi(gan, info.getLiuYueGanInfo());
            appendGanZhi(gan, info.getLiuRiGanInfo());
        } else {
            appendGanZhi(gan, info.getNianGanInfo());
            appendGanZhi(gan, info.getYueGanInfo());
            appendGanZhi(gan, info.getRiGanInfo());
            appendGanZhi(gan, info.getShiGanInfo());
        }
        return getHeHua(gan, new ArrayList<>());
    }

    public static List<HeHuaModel> getHeHuaZhi(BaZiInfo info, boolean uedDyLn) {
        ArrayList<String> gan = new ArrayList<>();

        ArrayList<String> zhi = new ArrayList<>();

        if (uedDyLn) {
            appendGanZhi(zhi, info.getDaYunZhiInfo());
            appendGanZhi(zhi, info.getLiuNianZhiInfo());
            appendGanZhi(zhi, info.getLiuYueZhiInfo());
            appendGanZhi(zhi, info.getLiuRiZhiInfo());
        } else {
            appendGanZhi(zhi, info.getNianZhiInfo());
            appendGanZhi(zhi, info.getYueZhiInfo());
            appendGanZhi(zhi, info.getRiZhiInfo());
            appendGanZhi(zhi, info.getShiZhiInfo());
        }
        return getHeHua(gan, zhi);
    }

    public static List<HeHuaModel> getTianYiGuiRenLiuRi(BaZiInfo info, List<String> tygr) {
        ArrayList<String> zhi = new ArrayList<>();
        appendGanZhi(zhi, info.getNianZhiInfo());
        appendGanZhi(zhi, info.getYueZhiInfo());
        appendGanZhi(zhi, info.getRiZhiInfo());
        appendGanZhi(zhi, info.getShiZhiInfo());
        List<String> gan = new ArrayList<>();
        List<HeHuaModel> heHuaModels = new ArrayList<>();
        Set<String> aa = new HashSet<>();
        for (int i = 0; i < tygr.size(); i++) {
            List<String> temp = new ArrayList<>(zhi);
            temp.add(tygr.get(i));
            List<HeHuaModel> heHua = getHeHua(gan, temp);
            for (HeHuaModel model : heHua) {
                if (!aa.contains(model.getName())) {
                    heHuaModels.add(model);
                    aa.add(model.getName());
                }
            }
        }
        return heHuaModels;
    }

    public static List<String> getTianYiGuiRen(BaZiInfo info) {
        String ng = info.getNianGanInfo().getName();
        String rg = info.getRiGanInfo().getName();
        Set<String> zhiList = new HashSet<>();
        String[] aa = new String[]{"甲戊:丑未", "乙己:申子", "丙丁:亥酉", "壬癸:卯巳", "庚辛:寅午"};
        for (String s : aa) {
            String[] split = s.split(":");
            if (split[0].contains(ng) || split[0].contains(rg)) {
                zhiList.add(split[1].substring(0, 1));
                zhiList.add(split[1].substring(1));
            }
        }
        return new ArrayList<>(zhiList);
    }


    public static DizhiShierlunModel getDizhiShierlun(String zhi) {
        return sDizhiSHierlunMap.get(zhi);
    }

    public static List<String> getCaiKu(BaZiInfo info) {
        List<String> list = new ArrayList<>();
        String s = sCaiKuMap.get(info.getNianZhiInfo().getName());
        if (s != null) {
            list.add(s);
        }
        s = sCaiKuMap.get(info.getYueZhiInfo().getName());
        if (s != null) {
            list.add(s);
        }
        s = sCaiKuMap.get(info.getRiZhiInfo().getName());
        if (s != null) {
            list.add(s);
        }
        s = sCaiKuMap.get(info.getShiZhiInfo().getName());
        if (s != null) {
            list.add(s);
        }
        if (list.isEmpty()) {
            list.add("无财库");
        }
        return list;
    }

    public static List<HeHuaModel> getHeHua(List<String> ganList, List<String> zhiList) {
        //去重
//        ganList = new ArrayList<>(new HashSet<>(ganList));
//        zhiList = new ArrayList<>(new HashSet<>(zhiList));
        List<HeHuaModel> list = new ArrayList<>();
        Set<String> ganSet = new HashSet<>();
        Set<String> zhiTwoSet = new HashSet<>();
        Set<String> zhiThreeSet = new HashSet<>();
        for (int i = 0; i < ganList.size(); i++) {
            for (int j = 0; j < ganList.size(); j++) {
                if (i != j) {
                    ganSet.add(ganList.get(i) + ganList.get(j));
                    ganSet.add(ganList.get(i) + ganList.get(i));
                }
            }
        }
        for (int i = 0; i < zhiList.size(); i++) {
            for (int j = 0; j < zhiList.size(); j++) {
                if (i != j) {
                    zhiTwoSet.add(zhiList.get(i) + zhiList.get(j));
                    zhiTwoSet.add(zhiList.get(j) + zhiList.get(i));
                }
            }
        }
        if (zhiList.size() >= 3) {
            for (int i = 0; i < zhiList.size(); i++) {
                for (int j = 0; j < zhiList.size(); j++) {
                    for (int k = 0; k < zhiList.size(); k++) {
                        if (k != i && k != j) {
                            String first = zhiList.get(i);
                            String second = zhiList.get(j);
                            String three = zhiList.get(k);
                            zhiThreeSet.add(first + second + three);
                            zhiThreeSet.add(first + three + second);

                            zhiThreeSet.add(second + first + three);
                            zhiThreeSet.add(second + three + first);

                            zhiThreeSet.add(three + first + second);
                            zhiThreeSet.add(three + second + first);
                        }
                    }
                }
            }
        }
        for (String key : ganSet) {
            HeHuaModel huaModel = sHeHuaMap.get(key);
            if (huaModel != null) {
                list.add(huaModel);
            }
        }
        for (String key : zhiTwoSet) {
            HeHuaModel huaModel = sHeHuaMap.get(key);
            if (huaModel != null) {
                list.add(huaModel);
            }
        }
        for (String key : zhiThreeSet) {
            HeHuaModel huaModel = sHeHuaMap.get(key);
            if (huaModel != null) {
                list.add(huaModel);
            }
        }
        return list;
    }

    public static List<CuiCaiDiLiFangWei> cuicaidili() {
        List<CuiCaiDiLiFangWei> list = new ArrayList<>();
        for (int i = 0; i < 60; i++) {
            String s = sLiuShiJiaZi.get(i);
            String gan = s.charAt(0) + "";
            String zhi = s.charAt(1) + "";
            TianGanModel tianGan = getTianGan(gan);
            DiZhiModel zhiInfo = getDiZhiInfo(zhi);
            if (tianGan.getWuXing().equals(zhiInfo.getWuXing())) {
                WuXingInfoModel xingInfo = getWuXingInfo(tianGan.getWuXing());
                list.add(new CuiCaiDiLiFangWei(s, tianGan.getWuXing(), xingInfo.getFangwei()));
            }
        }
        return list;
    }

    public static final String[][] nengLiangJiaQiang = new String[][]{
            new String[]{"金", "1.白色和田玉,阿富汗玉", "翡翠", "金发晶", "黄金白银\n",
                    "2.豆腐", "白萝卜", "薏仁", "白木耳", "白菜", "梨", "白芝麻\n",
                    "3.金色衣服", "白色衣服\n", "4.金蟾蜍", "金色家具风水摆件\n", "5.金色手机/电脑背景\n", "6.大树结拜兄弟\n", "7" +
                    ".阴历初一十五放生\n",
                    "8.手机号,车牌号,楼层号,常用密码酉4,申9\n", "9.字画\n", "10.装修风格,定做桌布,墙纸,窗帘,沙发罩\n",
                    "11.北斗七星灯阵\n", "12.改别名,字号,化名", "13.微信名字前后带造型小图标\n",
                    "14.五行音乐\n", "15.道家养生功法,打坐采气冥想(敲竹唤龟)\n", "16.方向能量补充\n",
                    "17.道家咒语 九字真言(临兵斗者皆阵列在前)\n", "18.种生基\n", "19.喝白茶\n", "20.喝白酒\n", "21.圆形\n"
            },
            new String[]{"水", "1.黑曜石", "青金石\n",
                    "2.葡萄", "黑豆", "黑木耳", "紫菜", "香菇", "黑芝麻", "黑米", "黑枸杞", "桑葚\n",
                    "3.蓝色衣服\n", "4.鱼缸", "蓝色家具风水摆件\n", "5.蓝色手机/电脑背景\n", "6.大树结拜兄弟\n", "7.阴历初一十五放生\n",
                    "8.手机号,车牌号,楼层号,常用密码子1,亥6\n", "9.字画\n", "10.装修风格,定做桌布,墙纸,窗帘,沙发罩\n",
                    "11.北斗七星灯阵", "12.改别名,字号,化名\n", "13.微信名字前后带造型小图标\n",
                    "14.五行音乐\n", "15.道家养生功法,打坐采气冥想(敲竹唤龟)\n", "16.方向能量补充\n",
                    "17.道家咒语 九字真言(临兵斗者皆阵列在前)\n", "18.种生基\n", "19.喝黑茶\n", "20.喝黑啤\n", "21.波浪形\n"
            },
            new String[]{"火", "1.玛瑙", "朱砂", "南红", "红翡翠", "红宝石\n",
                    "2.红萝卜", "番茄", "西瓜", "草莓", "辣椒", "枸杞", "红枣", "红心火龙果", "螃蟹", "虾\n",
                    "3.红色衣服", "4.红色家具风水摆件\n", "5.红色手机/电脑背景\n", "6.大树结拜兄弟\n", "7.阴历初一十五放生\n",
                    "8.手机号,车牌号,楼层号,常用密码巳2,午7\n", "9.字画\n", "10.装修风格,定做桌布,墙纸,窗帘,沙发罩\n",
                    "11.北斗七星灯阵\n", "12.改别名,字号,化名\n", "13.微信名字前后带造型小图标\n",
                    "14.五行音乐\n", "15.道家养生功法,打坐采气冥想(敲竹唤龟)\n", "16.方向能量补充\n",
                    "17.道家咒语 九字真言(临兵斗者皆阵列在前)\n", "18.种生基\n", "19.喝红茶\n", "20.喝红酒\n", "21.三角形\n"
            },
            new String[]{"木", "1.和田玉", "墨玉", "绿翡翠", "木质材料饰品", "独山玉", "绿幽灵水晶\n",
                    "2.芹菜", "韭菜", "菠菜", "绿豆", "葱", "猕猴桃\n",
                    "3.绿色衣服\n", "4.小绿植", "绿色家具风水摆件\n", "5.绿色手机/电脑背景\n", "6.大树结拜兄弟\n", "7" +
                    ".阴历初一十五放生\n",
                    "8.手机号,车牌号,楼层号,常用密码寅3,卯8\n", "9.字画\n", "10.装修风格,定做桌布,墙纸,窗帘,沙发罩\n",
                    "11.北斗七星灯阵\n", "12.改别名,字号,化\n名", "13.微信名字前后带造型小图标\n",
                    "14.五行音乐\n", "15.道家养生功法,打坐采气冥想(敲竹唤龟)\n", "16.方向能量补充\n",
                    "17.道家咒语 九字真言(临兵斗者皆阵列在前)\n", "18.种生基\n", "19.喝绿茶\n", "20.喝竹叶青,日本清酒\n", "21" +
                    ".长方形\n"
            },
            new String[]{"土", "1.黄龙玉", "和田玉", "黄色翡翠", "琥珀", "蜜蜡\n",
                    "2.黄豆", "花生", "玉米", "木瓜", "南瓜", "莲子", "凤梨", "杨桃", "橙\n",
                    "3.棕色衣服\n", "4.棕色,黄色家具风水摆件\n", "5.棕色手机/电脑背景\n", "6.大树结拜兄弟\n", "7.阴历初一十五放生\n",
                    "8.手机号,车牌号,楼层号,常用密码辰戌5,丑未0\n", "9.字画\n", "10.装修风格,定做桌布,墙纸,窗帘,沙发罩\n",
                    "11.北斗七星灯阵\n", "12.改别名,字号,化名\n", "13.微信名字前后带造型小图标\n",
                    "14.五行音乐\n", "15.道家养生功法,打坐采气冥想(敲竹唤龟)\n", "16.方向能量补充\n",
                    "17.道家咒语 九字真言(临兵斗者皆阵列在前)\n", "种生基\n", "喝黄茶\n", "喝啤酒\n", "正方形\n"
            },
    };

    public static String getNengLiangBuChongFangShi(String wuxing) {
        StringBuilder sb = new StringBuilder();
        for (String[] arr : nengLiangJiaQiang) {
            if (arr[0].equals(wuxing)) {
                for (int i = 1; i < arr.length; i++) {
                    sb.append(arr[i]);
                }
            }
        }
        return sb.toString();
    }


    public static List<BaZhiHistory> getTimeByBaZi(List<String> bzArr, int gender) {
        //获取年份
        List<BaZhiHistory> histories = new ArrayList<>();
        //1911
        int yearNoIndex = sLiuShiJiaZi.indexOf(bzArr.get(0)) + 1804;
//        int yearNoIndex = sLiuShiJiaZi.indexOf(bzArr.get(0)) + 1924;
        String yue = bzArr.get(1);
        StringBuilder queueBz = new StringBuilder();
        for (String s : bzArr) {
            queueBz.append(s);
        }
        String yueZhi = yue.toCharArray()[1] + "";
        int yueIndex = ((Arrays.asList(Zhi).indexOf(yueZhi) + 10) % 12) + 1;
        String shiZhi = bzArr.get(3).toCharArray()[1] + "";
        int shiIndex = Arrays.asList(Zhi).indexOf(shiZhi) * 2;
        StringBuilder sb2 = new StringBuilder();
        sInitHelper.d("bbb=>" + yearNoIndex);
        for (int year = yearNoIndex; year < 2050; year += 60) {
            Lunar lunar = Lunar._fromYmdHms(year - 1, 11, 1, shiIndex, 0, 0);
            int index = 0;
            while (index < 420) {
                List<String> baZi = lunar.getBaZi();
                sb2.setLength(0);
                for (String s : baZi) {
                    sb2.append(s);
                }
                if (queueBz.toString().equals(sb2.toString())) {

                    Solar solar = lunar.getSolar();
                    sInitHelper.d(solar.toYmd() + "," + lunar.toSimpleString() + " =>" + sb2 + " " +
                            " ," + queueBz);
                    BaZhiHistory history = new BaZhiHistory(solar.calendar.getTime(),
                            System.currentTimeMillis(), "a"
                            , "北京", 0, gender);
                    histories.add(history);
                    break;
                }
                lunar = lunar.next(1);
                index++;
            }
        }
        return histories;
    }

    public static String getXunShou(String ganZhi) {
        int index = sLiuShiJiaZi.lastIndexOf(ganZhi);
        for (int i = 0; i < sLiuShiJiaZi.size(); i++) {
            String gz = sLiuShiJiaZi.get(index - i);
            if (gz.startsWith("甲")) {
                return gz;
            }
        }
        return "未找到";
    }


    private static QiMenDunJiaItem getDunJia(List<QiMenDunJiaItem> list, int gongNum) {
        for (QiMenDunJiaItem s : list) {
            if (s.getGongNum() == gongNum) {
                return s;
            }
        }
        return null;
    }

    public static String getDiPanGan(List<QiMenDunJiaItem> list, int gongNum) {
        QiMenDunJiaItem dunJia = getDunJia(list, gongNum);
        if (dunJia != null) {
            return dunJia.getDiPanGan();
        }
        return "";
    }

    public static QiMenDunJiaModel printQiMenBaGua(Solar solar) {
        return printQiMenBaGua(solar, "无");
    }

    public static QiMenDunJiaModel printQiMenBaGua(Solar solar, String ju) {
        QiMenDunJiaModel model = new QiMenDunJiaModel();
        Lunar lunar = solar.getLunar();
        model.setLunar(lunar);
        model.setSolar(solar);

        Map<Integer, IQiMenDunJiaTask> taskMap = new HashMap<>();
        taskMap.put(1, new QiMenDunJiaStep1Task(model));
        taskMap.put(2, new QiMenDunJiaStep2Task(model, ju));
        taskMap.put(3, new QiMenDunJiaStep3Task(model));
        taskMap.put(4, new QiMenDunJiaStep4Task(model));
        taskMap.put(5, new QiMenDunJiaStep5Task(model));
        taskMap.put(6, new QiMenDunJiaStep6Task(model));
        taskMap.put(7, new QiMenDunJiaStep7Task(model));

        int step = 8;


        for (int i = 1; i < step; i++) {
            IQiMenDunJiaTask task = taskMap.get(i);
            if (task != null) {
                task.handleTask();
            }
        }
        model.handleItem();
        List<QiMenDunJiaItem> list = model.getList();
        StringBuilder sb = new StringBuilder();
        for (QiMenDunJiaItem dunJia : list) {
            sb.append(dunJia.getGua()).append(dunJia.getGongNum())
                    .append("\t").append(dunJia.getShen())
                    .append(",").append(dunJia.getTianPanGan())
                    .append("\t").append(dunJia.getDiPanGan())
                    .append(dunJia.getDiPanCangGan())
                    .append("\t").append(dunJia.getXing())
                    .append("\t").append(dunJia.getMen())
                    .append("\t").append(dunJia.getHuanHang());
        }
//        System.out.println(sb);
        return model;
    }

    public static String getJiuXingBall(String men) {
        //3、九星取数法
        //天逢16、天芮2058、天冲34、天辅45、天禽50、天心61、天柱27、天任7058、天英39
        //天蓬星①、天任星⑧、天冲星③、天辅星④、天禽星⑤、天英星⑨、天芮星②、天柱星⑦、天心星⑥。
        switch (men) {
            case "天蓬":
                return "1";
            case "天芮":
                return "2";
            case "天冲":
                return "3";
            case "天辅":
                return "4";
            case "天禽":
                return "5";
            case "天心":
                return "6";
            case "天柱":
                return "7";
            case "天任":
                return "8";
            case "天英":
                return "9";
            default:
                return "";
        }
    }

    public static String getShenBall(String shen) {
        //值符①、滕蛇⑧、太阴③、六合④、明王⑤、白虎⑨、玄武②、九地⑦、九天⑥。
        switch (shen) {
            case "值符":
                return "1";
            case "玄武":
                return "2";
            case "太阴":
                return "3";
            case "六合":
                return "4";
            case "九天":
                return "6";
            case "九地":
                return "7";
            case "腾蛇":
                return "8";
            case "白虎":
                return "9";
            default:
                return "";
        }
    }

    public static String getMenBall(String men) {
        //2、九宫取数法
        //坎宫16、坤宫2058、震宫34、巽宫45、中宫50、乾宫61、兑宫27、艮宫7058、离宫39
        //4、八门取数法
        //休门16、死门2058、伤门34、杜门45、开门61、惊门27、生门7058景门39
//        switch (men) {
//            case "休门":
//                return "16";
//            case "死门":
//                return "2058";
//            case "伤门":
//                return "34";
//            case "杜门":
//                return "45";
//            case "开门":
//                return "61";
//            case "惊门":
//                return "27";
//            case "生门":
//                return "7058";
//            case "景门":
//                return "39";
//            default:
//                return "";
//        }
        //休门①、生门⑧、伤门③、杜门④、中门⑤、景门⑨、死门②、惊门⑦、开门⑥。
        switch (men) {
            case "休门":
                return "1";
            case "死门":
                return "2";
            case "伤门":
                return "3";
            case "杜门":
                return "4";
            case "开门":
                return "6";
            case "惊门":
                return "7";
            case "生门":
                return "8";
            case "景门":
                return "9";
            default:
                return "";
        }
    }

    private static Map<String, String> readFc3DNum() {
        //2024131|2024-05-20(一)|0,6,9
        Map<String, String> map = new HashMap<>();

        try (BufferedReader br = new BufferedReader(new InputStreamReader(DataUtils.openFile(
                "fc3d.txt")))) {
            String line;
            while ((line = br.readLine()) != null) {
                map.put(line.substring(8, 18), line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    }

    private static Map<String, String> readTcp3Num() {
        //2024131|2024-05-20(一)|0,6,9
        Map<String, String> map = new HashMap<>();

        try (BufferedReader br = new BufferedReader(new InputStreamReader(DataUtils.openFile(
                "tcp3.txt")))) {
            String line;
            while ((line = br.readLine()) != null) {
                map.put(line.substring(6, 16), line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    }

    public static Fc3DModel getFc3DOpenDate(String yyyymmss) {
        return new Fc3DModel(sFc3DOpenNumMap.get(yyyymmss));
    }

    public static Fc3DModel getTcp3OpenDate(String yyyymmss) {
        return new Fc3DModel(sTcp3OpenNumMap.get(yyyymmss));
    }

    public static boolean isJiXing(String gan, int gong) {
        //甲子戊落震三宫，甲戌己落坤二宫，甲申庚落艮八宫，甲午辛落离九宫，甲辰壬落巽四宫，甲寅癸落巽四宫
        for (int i = 0; i < gan.length(); i++) {
            String flag = gan.charAt(i) + "" + gong;
            switch (flag) {
                case "戊3":
                case "己2":
                case "庚8":
                case "辛9":
                case "壬4":
                case "癸4":
                    return true;
            }
        }
        return false;
    }

    public static boolean isRuMu(String gan, int gong) {
        //乙、丙、戊落乾宫为入墓；甲、癸落坤宫为入墓；丁、己、庚落艮宫为入墓；辛、壬落巽宫为入墓
        for (int i = 0; i < gan.length(); i++) {
            String flag = gan.charAt(i) + "" + gong;
            switch (flag) {
                case "乙6":
                case "丙6":
                case "戊6":
                case "甲2":
                case "癸2":
                case "丁8":
                case "己8":
                case "庚8":
                case "辛4":
                case "壬4":
                    return true;
            }
        }
        return false;
    }

    public static boolean isPoGong(String men, int gong) {
        String flag = men + gong;
        switch (flag) {
            case "休门9":  //休门（水）落（克）离宫（火）；
            case "生门1":  //生门（土）落（克）坎宫（水）；
            case "伤门8":   //伤门（木）落（克）艮宫、坤宫（土）；
            case "伤门2":
            case "杜门8":   //杜门（木）落（克）艮宫、坤宫（土）；
            case "杜门2":
            case "景门6":    //景门（火）落（克）乾宫、兑官（金）；
            case "景门7":
            case "死门1":      //死门（土）落（克）坎宫（水）；
            case "惊门3":      //惊门（金）落（克）震宫、巽宫（木）；
            case "惊门4":
            case "开门3":       //开门（金）落（克）震宫、巽宫（木）；
            case "开门4":
                return true;
        }
        return false;
    }

    public static String getQiMenDunJiaJu(String ju) {
        for (QiMenDunJiaJuModel value : sQiMenDunJiaJu.values()) {
            if (ju.equals(value.getJuName())) {
                return value.getDesc();
            }
        }
        return "";
    }

    public static List<String> getQiMenDunJiaJu(QiMenDunJiaModel model, QiMenDunJiaItem item) {
        List<String> juList = new ArrayList<>();
        if (item.getGongNum() == 5) {
            return juList;
        }
        String tianPan = item.getTianPanGan();
        String diPan = item.getDiPanGan();
        String men = item.getMen();
        String shen = item.getShen();
        int gongNum = item.getGongNum();
        String zhiMen = model.getZhiMen();
        if (tianPan.contains("戊") && diPan.contains("丙")) {
            juList.add("青龙返首");
        }
        if (tianPan.contains("丙") && diPan.contains("戊")) {
            juList.add("飞鸟跌穴");
        }
        //九遁
        if (tianPan.contains("丙") && diPan.contains("丁") && men.contains("生门")) {
            juList.add("天遁");
        }
        if (tianPan.contains("乙") && diPan.contains("己") && men.contains("开门")) {
            juList.add("地遁");
        }
        if (tianPan.contains("丁") && shen.contains("太阴") && men.contains("休门")) {
            juList.add("人遁");
        }
        boolean flag1 = men.contains("开门") || men.contains("休门") || men.contains("生门");
        if (tianPan.contains("乙") && flag1 && gongNum == 4) {
            juList.add("风遁");
        }
        if (tianPan.contains("乙") && flag1 && (diPan.contains("辛"))) {
            juList.add("云遁");
        }
        //龙遁：天盘乙奇（日奇），门盘开、休、生之一之一，地盘坎（水中有龙）一宫或六癸
        if (tianPan.contains("乙") && flag1 && (gongNum == 1 || diPan.contains("癸"))) {
            juList.add("龙遁");
        }
        boolean flag2 = men.contains("休门") || men.contains("生门");
        //虎遁：天盘乙奇（日奇），合休门或生门，临地盘六辛于艮（寅虎）八宫，或天盘甲申庚合开门下临地盘兑宫（庚辛金，均为白虎）都称为虎遁
        if (tianPan.contains("乙") && flag2 && (gongNum == 8 || diPan.contains("辛"))) {
            juList.add("虎遁");
        }
        if (tianPan.contains("庚") && men.contains("开门") && gongNum == 7) {
            juList.add("虎遁");
        }
        //神遁：天盘丙奇（月奇），门盘杜门、神盘九天（九天之神）
        if (tianPan.contains("丙") && men.contains("杜门") && shen.contains("九天")) {
            juList.add("神遁");
        }
        //鬼遁：天盘丁奇（星奇），门盘杜门（人间门被堵住），神盘九地（地狱有鬼）
        if (tianPan.contains("丁") && men.contains("杜门") && shen.contains("九地")) {
            juList.add("鬼遁");
        }
        boolean isQiFlag = tianPan.contains("乙") || tianPan.contains("丙") || tianPan.contains("丁");
        //三奇得使就是天盘乙、丙、丁加临地盘值使门，具体而言，就是天盘乙奇加临地盘甲戌己或甲午辛，天盘丙奇加临地盘甲子戊或甲申庚，天盘丁奇加临地盘甲辰壬或甲寅癸。
        if (isQiFlag && men.contains(zhiMen)) {
            juList.add("三奇得使");
        }
        //丁奇又名玉女。玉女守门，就是门盘值使门所落之宫正遇地盘丁奇
        if (tianPan.contains("丁") && shen.contains("值符")) {
            juList.add("玉女守门");
        }
        if (tianPan.contains("丙") && shen.contains("值符")) {
            juList.add("青龙反首");
        }
        //乙奇临震宫，为日出扶桑，有禄之乡，是贵人升于乙卯正殿。
        // 丙奇到离宫，为月照端门，火旺之地，是贵人升于丙午正殿。
        // 丁奇到兑宫，为星见西方，（酉为丁火生生之地）天之神位，是贵人升于丁酉正殿。
        if ((tianPan.contains("乙") && gongNum == 3)
                || (tianPan.contains("丙") && gongNum == 9)
                || (tianPan.contains("丁") && gongNum == 7)
        ) {
            juList.add("三奇贵人升殿");
        }
        //7、天显时格（又名天辅大吉时） 甲、己日的甲子时、甲戌时，乙、庚日的甲申时，丙、辛日的甲午时，丁、壬日的甲辰时，戊、癸日的甲寅时
        List<String> baZi = model.getLunar().getBaZi();
        String riGan = baZi.get(2).charAt(0) + "";
        String shiZhu = baZi.get(3);
        if ((riGan.startsWith("甲") && shiZhu.equals("甲子"))
                || (riGan.startsWith("己") && shiZhu.equals("甲戌"))
                || ((riGan.startsWith("乙") || riGan.startsWith("庚")) && shiZhu.equals("甲申"))
                || ((riGan.startsWith("丙") || riGan.startsWith("辛")) && shiZhu.equals("甲午"))
                || ((riGan.startsWith("丁") || riGan.startsWith("壬")) && shiZhu.equals("甲辰"))
                || ((riGan.startsWith("戊") || riGan.startsWith("癸")) && shiZhu.equals("甲寅"))
        ) {
            juList.add("天显时格");
        }
        //三诈五假 具体而言，三吉门合三奇上乘太阴者，叫真诈。三吉门合三奇上乘六合者，叫休诈。三吉门合三奇上乘九地者，叫重诈。
        if (flag1 && shen.equals("太阴")) {
            juList.add("真诈");
        }
        if (flag1 && shen.equals("九地")) {
            juList.add("重诈");
        }
        if (flag1 && shen.equals("六合")) {
            juList.add("休诈");
        }
        //五假，是天假、地假、人假、神假、鬼假
        if (isQiFlag && men.equals("景门") && shen.equals("天假")) {
            juList.add("天假");
        }
        boolean b = tianPan.contains("丁") || tianPan.contains("己") || tianPan.contains("癸");
        //丁、己、癸
        //九地或太阴或六合
        if (b &&
                men.equals("杜门") && "九地太阴六合".contains(shen)) {
            juList.add("地假");
        }
        //惊门合六壬上乘九天，叫人假
        if (tianPan.contains("壬") && men.equals("惊门") && "九天".contains(shen)) {
            juList.add("人假");
        }
        //伤门合丁、己、癸，上乘九地，叫神假（又叫物假）
        if (b && men.equals("伤门") && "九地".contains(shen)) {
            juList.add("神假");
        }
        //死门合丁、己、癸，上乘九地，叫喊鬼假（又叫神假
        if (b && men.equals("死门") && "九地".contains(shen)) {
            juList.add("神假");
        }
        //三奇乙、丙、丁，四吉神太阴、六合、九地、九天，三吉门开、休、生，各有其一，共临其方位，为吉道清灵，用事俱吉
        if (isQiFlag && "开门休门生门".contains(men) && "太阴六合九地九天".contains(shen)) {
            juList.add("三奇之灵");
        }
        //10、奇游禄位 乙奇到震（卯为乙木临官禄地），丙奇到巽(巳为丙火临官禄地),丁奇到离(午为丁火临官禄地)为本禄之位，合三吉门，宜上官赴任，求财祈福等各种谋为都吉利
        if ((tianPan.contains("乙") && gongNum == 3)
                || tianPan.contains("丙") && gongNum == 4
                || tianPan.contains("丁") && gongNum == 5
        ) {
            juList.add("奇游禄位");
        }
        //11、欢怡
        if (isQiFlag && shen.contains("值符")
        ) {
            juList.add("欢怡");
        }
        //12、奇仪相合 乙庚、丙辛、丁壬为奇合，戊癸、甲己为仪合，得吉门
//        if (isQiFlag && shen.contains("值符")
//        ) {
//            juList.add("欢怡");
//        }
        //13、门宫和义

        List<String> tianDiPan = item.getTianDiPan();
        for (String ganZhi : tianDiPan) {
            QiMenDunJiaJuModel juModel = sQiMenDunJiaJu.get(ganZhi);
            if (juModel != null) {
                juList.add(juModel.getJuName());
            }
        }

        //奇格 天盘六庚，加地盘乙、丙、丁三奇
        if (tianPan.contains("庚") && (diPan.contains("乙") || diPan.contains("丙") || diPan.contains("丁"))) {
            juList.add("奇格");
        }


        //岁格 天盘六庚，加地盘年干
        String nianGan = baZi.get(0).charAt(0) + "";
        String yueGan = baZi.get(1).charAt(0) + "";
        String shiGan = baZi.get(3).charAt(0) + "";
        if (tianPan.contains("庚") && (diPan.contains(nianGan))) {
            juList.add("岁格");
        }
        //月格 天盘六庚，加地盘月干
        if (tianPan.contains("庚") && (diPan.contains(yueGan))) {
            juList.add("月格");
        }
        //15、日格（又叫“伏干格”） 天盘六庚，加地盘日干
        if (tianPan.contains("庚") && (diPan.contains(riGan))) {
            juList.add("日格");
        }

        //16、飞干格 天盘日干，加地盘六庚
        if (tianPan.contains(riGan) && diPan.contains("庚")) {
            juList.add("飞干格");
        }

        //17、时格 天盘六庚，加地盘时干
        if (tianPan.contains("庚") && (diPan.contains(shiGan))) {
            juList.add("时格");
        }
        //18、六仪击刑 天盘值符，加地盘与值符相刑的宫
        return juList;
    }


    public static QiMenDunJiaXingModel getXingModel(String xing) {
        return sQiMenDunJiaJiuXing.get(xing);
    }

    public static String getXingWang(String xing, Object zhiOrGong) {
        return sQiMenDunJiaJiuXingWang.get(xing + zhiOrGong);
    }

    public static QiMenDunJiaInfoModel getQiMenDunJiaBaShen(String shen) {
        return sQiMenDunJiaBaShen.get(shen);
    }

    public static QiMenDunJiaInfoModel getQiMenDunJiaBaMen(String shen) {
        return sQiMenDunJiaBaMen.get(shen);
    }


    public static List<String> getJiShi(String shiZhu) {
        //子午从申起，丑未由戌寻，
        // 寅申瞧子上，卯酉却在寅；
        // 辰戌把辰数，巳亥觅午根。
        List<String> result = new ArrayList<>();
        String shiZhi = shiZhu.charAt(1) + "";
        String target = "";
        if ("子午".contains(shiZhi)) {
            target = "申";
        } else if ("丑未".contains(shiZhi)) {
            target = "戌";
        } else if ("寅申".contains(shiZhi)) {
            target = "子";
        } else if ("卯酉".contains(shiZhi)) {
            target = "寅";
        } else if ("辰戌".contains(shiZhi)) {
            target = "辰";
        } else if ("巳亥".contains(shiZhi)) {
            target = "午";
        }
        int index = 0;
        for (int i = 0; i < Zhi.length; i++) {
            String zhi = Zhi[i];
            if (zhi.equals(target)) {
                index = i;
            }
        }
        int[] arr = new int[]{0, 1, 4, 5, 7, 10};
        for (int num : arr) {
            result.add(Zhi[(num + index) % 12]);
        }
        //道远几时通达路遥何日还乡
        return result;
    }

    public static List<String> getJiRi(String shiZhu) {
        //正七起子二八寅，三九原来就在辰； 
        //四十两月从午起，五和十一往申觅； 
        //尚有两月未明了，六与十二把戌寻
        List<String> result = new ArrayList<>();
        String shiZhi = shiZhu.charAt(1) + "";
        String target = "";
        //  "子",    // 11
        //            "丑",    //12
        //            "寅",    //1
        //            "卯",    //2
        //            "辰",    //3
        //            "巳",    //4
        //            "午",    //5
        //            "未",    //6
        //            "申",    //7
        //            "酉",    //8
        //            "戌",    //9
        //            "亥"     //10
        if ("寅申".contains(shiZhi)) { //正七起子
            target = "子";
        } else if ("卯酉".contains(shiZhi)) { //二八寅
            target = "寅";
        } else if ("午子".contains(shiZhi)) {//五和十一往申
            target = "申";
        } else if ("未丑".contains(shiZhi)) {//六与十二把戌
            target = "戌";
        } else if ("辰戌".contains(shiZhi)) {//三九原来就在辰
            target = "辰";
        } else if ("巳亥".contains(shiZhi)) {//四十两月从午起
            target = "午";
        }
        int index = 0;
        for (int i = 0; i < Zhi.length; i++) {
            String zhi = Zhi[i];
            if (zhi.equals(target)) {
                index = i;
            }
        }
        int[] arr = new int[]{0, 1, 4, 5, 7, 10};
        for (int num : arr) {
            result.add(Zhi[(num + index) % 12]);
        }
        return result;
    }


    private static void appendNum(String targetStr, Map<Integer, List<String>> map, int num,
                                  String sb) {
        if (targetStr.contains(sb)) {
            List<String> list = map.computeIfAbsent(num, k -> new ArrayList<>());
            list.add(sb);
        }
    }


    public static void getFc3DOpenGan(Fc3DOpenModel openModel, String ju) {
        String[] split = openModel.getDate().split("-");
        Solar solar = Solar.fromYmdHms(Integer.parseInt(split[0]), Integer.parseInt(split[1]),
                Integer.parseInt(split[2]), sHour, sMinute, 45);
        String tianPanYong = "乙丙丁";
        String menPanYong = "景门开门生门";
        String xingPanYong = "天辅天柱";
        String shenPanYong = "六合太阴九地";
        QiMenDunJiaModel model = printQiMenBaGua(solar, ju);
        List<QiMenDunJiaItem> modelList = model.getList();
        Fc3DModel fc3DModel = openModel.getModel();
        List<Integer> nums = fc3DModel.getNums();
        for (QiMenDunJiaItem jiaItem : modelList) {
            boolean isOpenGong = nums.contains(jiaItem.getGongNum());
            if (!isOpenGong) {
                continue;
            }
            if (jiaItem.getGongNum() == 5) {
                jiaItem = modelList.get(2);
            }
            for (char c : jiaItem.getTianPanGan().toCharArray()) {
                String str = c + "";
                if (tianPanYong.contains(str)) {
                    openModel.appendGan(str);
                }
            }
            if (menPanYong.contains(jiaItem.getMen())) {
                openModel.appendMen(jiaItem.getMen());
            }
            if (xingPanYong.contains(jiaItem.getXing())) {
                openModel.appendXing(jiaItem.getXing());
            }
            if (shenPanYong.contains(jiaItem.getShen())) {
                openModel.appendShen(jiaItem.getShen());
            }
        }
    }

    public static String getLastFiveDayQmdj(Solar solar, String ju) {
        long time = solar.getCalendar().getTime() - 5 * 86400 * 1000;
        Solar cur = Solar.fromDate(ExactDate.fromTimeInMillis(time));
        String tianPanYong = "乙丙丁";
        String menPanYong = "景门开门生门";
        String xingPanYong = "天辅天柱";
        String shenPanYong = "六合太阴九地";
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 6; i++) {
            QiMenDunJiaModel model = printQiMenBaGua(cur, ju);
            Fc3DModel fc3DModel = getFc3DOpenDate(cur.toYmd());
            Map<Integer, List<String>> panMap = new HashMap<>();
            List<QiMenDunJiaItem> modelList = model.getList();
            sb.append(cur.toYmd()).append("3D开奖:");
            for (QiMenDunJiaItem jiaItem : modelList) {
                for (char c : jiaItem.getTianPanGan().toCharArray()) {
                    String str = c + "";
                    appendNum(tianPanYong, panMap, jiaItem.getGongNum(), str);
                }
                appendNum(menPanYong, panMap, jiaItem.getGongNum(), jiaItem.getMen());
                appendNum(xingPanYong, panMap, jiaItem.getGongNum(), jiaItem.getXing());
                appendNum(shenPanYong, panMap, jiaItem.getGongNum(), jiaItem.getShen());
            }
            for (Integer num : fc3DModel.nums) {
                sb.append(num);
                List<String> list = panMap.get(num);
                if (list != null) {
                    sb.append("(");
                    for (int j = 0; j < list.size(); j++) {
                        sb.append(list.get(j));
                        if (j != list.size() - 1) {
                            sb.append(",");
                        }
                    }
                    sb.append(")");
                }
                sb.append("  ,");
            }
            sb.append("\n");
            cur = cur.next(1, false);
        }
        sb.append("\n");
        time = solar.getCalendar().getTime() - 5 * 86400 * 1000;
        cur = Solar.fromDate(ExactDate.fromTimeInMillis(time));
        for (int i = 0; i < 6; i++) {
            QiMenDunJiaModel model = printQiMenBaGua(cur, ju);
            Fc3DModel fc3DModel = getTcp3OpenDate(cur.toYmd());
            Map<Integer, List<String>> panMap = new HashMap<>();
            List<QiMenDunJiaItem> modelList = model.getList();
            sb.append(cur.toYmd()).append("排3开奖:");
            for (QiMenDunJiaItem jiaItem : modelList) {
                for (char c : jiaItem.getTianPanGan().toCharArray()) {
                    String str = c + "";
                    appendNum(tianPanYong, panMap, jiaItem.getGongNum(), str);
                }
                appendNum(menPanYong, panMap, jiaItem.getGongNum(), jiaItem.getMen());
                appendNum(xingPanYong, panMap, jiaItem.getGongNum(), jiaItem.getXing());
                appendNum(shenPanYong, panMap, jiaItem.getGongNum(), jiaItem.getShen());
            }
            for (Integer num : fc3DModel.nums) {
                sb.append(num);
                List<String> list = panMap.get(num);
                if (list != null) {
                    sb.append("(");
                    for (int j = 0; j < list.size(); j++) {
                        sb.append(list.get(j));
                        if (j != list.size() - 1) {
                            sb.append(",");
                        }
                    }
                    sb.append(")");
                }
                sb.append("  ,");
            }
            sb.append("\n");
            cur = cur.next(1, false);
        }
        return sb.toString();
    }

    public static class Fc3DModel {
        //2024209|2024-08-06(二)|6,7,6
        private String qi;
        private String date;
        private List<Integer> nums = new ArrayList<>();

        public Fc3DModel(String str) {
            if (str == null || str.length() == 0) {
                return;
            }
            String[] split = str.split("\\|");
            qi = split[0];
            date = split[1];
            String[] strings = split[2].split(",");

            for (String num : strings) {
                nums.add(Integer.parseInt(num));
            }
        }

        public String getQi() {
            return qi;
        }

        public String getDate() {
            return date;
        }

        public List<Integer> getNums() {
            return nums;
        }
    }

    public static String getDunJiaItemGan(QiMenDunJiaItem item) {
        String panGan = item.getTianPanGan();
        String diPan = item.getDiPanGan();
        int length = panGan.length();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            String tpgan = panGan.charAt(i) + "";
            int len = diPan.length();
            for (int j = 0; j < len; j++) {
                String dpgan = diPan.charAt(j) + "";
                QiMenDunJiaJuModel juModel = sQiMenDunJiaJu.get(tpgan + dpgan);
                if (juModel != null) {
                    sb.append(juModel.getTianPanDiPan()).append(":").append(juModel.getJuName()).append("\n");
                }
            }
        }
        return sb.toString();
    }

    public static String getDunJiaItemMenLuoGong(QiMenDunJiaItem item) {
        // 景門-吉
        String key = item.getMen() + item.getGongNum();
        QiMenDunJiaInfoModel model = sQiMenDunJiaBaWangXiang.get(key);
        if (model == null) {
            return item.getMen();
        }
        QiMenDunJiaInfoModel infoModel = sQiMenDunJiaBaMenLuoGong.get(key);
        if (infoModel == null) {
            return item.getMen();
        }
        return item.getMen() + "-" + infoModel.getYuYi() + "-" + infoModel.getDesc() + "-" + model.getDesc();
    }

    public static String getDunJiaItemXingLuoGong(QiMenDunJiaItem item) {
        // 天任(休)-凶
        QiMenDunJiaInfoModel model = sQiMenDunJiaBaWangXiang.get(item.getXing() + item.getGongNum());
        if (model == null) {
            return item.getXing();
        }
        return item.getXing() + "(" + model.getDesc() + ")";
    }

    public static String getDunJiaItemShenLuoGong(QiMenDunJiaItem item) {
        String status = "吉";
        switch (item.getShen()) {
            case "腾蛇":
            case "白虎":
            case "玄武":
                status = "凶";
                break;
        }
        return item.getShen() + "-" + status;
    }

    //景门+宫位
    //值使+八神
    //生门+宫位
    //八神,九宫,八门
    public static String getGupiao(String key) {
        return sGuPiaoMap.get(key);
    }

    public static String getShengKe(String gong1, String gong2) {
        EightDagramsModel model1 = null;
        String wuxing2 = null;
        for (EightDagramsModel dagramsModel : sEightDagramsModels) {
            if (dagramsModel.getEightDiagramsName().equals(gong1)) {
                model1 = dagramsModel;
            }
            if (dagramsModel.getEightDiagramsName().equals(gong2)) {
                wuxing2 = dagramsModel.getWuXing();
            }
        }
        if (model1 != null && wuxing2 != null) {
            String wuXingSheng = model1.getWuXingSheng();
            String wuXingKe = model1.getWuXingKe();
            if (wuXingSheng.equals(wuxing2)) {
                return "生";
            }
            if (wuXingKe.equals(wuxing2)) {
                return "克";
            }
        }
        return "无";
    }

    public static LhcBean getLhcInfo(String date) {
        LogUtils.d("getLhcInfo: "+date + ","+ sXglhcMap.get(date));
        return sXglhcMap.get(date);
    }

    public static List<LhcBean> getLhc(String ju) {
        ArrayList<String> list = new ArrayList<>(sXglhcMap.keySet());
        list.sort(Comparator.reverseOrder());
        List<LhcBean> result = new ArrayList<>();
        for (String s : list) {
            result.add(sXglhcMap.get(s));
        }
        return result;
    }

    private static String getDzBySx(String zhi) {
        switch (zhi) {
            case "马":
                return "午";
            case "羊":
                return "未";
            case "猴":
                return "申";
            case "鸡":
                return "酉";
            case "狗":
                return "戌";
            case "猪":
                return "亥";
            case "鼠":
                return "子";
            case "牛":
                return "丑";
            case "虎":
                return "寅";
            case "兔":
                return "卯";
            case "龙":
                return "辰";
            case "蛇":
                return "巳";
        }
        return "";
    }
    public static List<LhcBean> getLhcQmdj(String year,String ju,String hour) {
        //2024 1蛇 2 龙 3 兔 4 虎 5 牛
        //2023 1龙
        ArrayList<String> list = sXglhcMap.keySet().stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.startsWith(year);
            }
        }).sorted(Comparator.reverseOrder()).collect(Collectors.toCollection(ArrayList::new));
        List<LhcBean> result = new ArrayList<>();
        int shangMenCount = 0;
        int kaiMenCount = 0;
        int zhiFuCount = 0;
        int zhiShiCount = 0;
        int riCount = 0;
        int shiCount = 0;
        int num =  list.size();
        for (String s : list) {
            LhcBean bean = sXglhcMap.get(s);
            String[] split = bean.getDate().split("-");
            Solar solar = Solar.fromYmdHms(Integer.parseInt(split[0]), Integer.parseInt(split[1]),
                    Integer.parseInt(split[2]) ,Integer.parseInt(hour), 30, 1);
            String animal = bean.getTx().getAnimal();
            String txDz = getDzBySx(animal);
//            List<String> jiShi = DataUtils.getJiShi(solar.getLunar().getBaZi().get(2));
//            if (jiShi.contains(txDz)){
//                shiCount++;
//            }
            QiMenDunJiaModel model = printQiMenBaGua(solar, ju);
            List<QiMenDunJiaItem> modelList = model.getList();
            for (QiMenDunJiaItem jiaItem : modelList) {
                String panZhi = jiaItem.getDiPanZhi();
                if (panZhi.contains(txDz)){
                    if (jiaItem.getMen().equals("伤门")){
                        shangMenCount++;
                    }
                    if (jiaItem.getMen().equals("开门")){
                        kaiMenCount++;
                    }
                    if (jiaItem.isRiGan()){
                        riCount++;
                    }
                    if (jiaItem.isShiGan()){
                        shiCount++;
                    }
                    if (jiaItem.isZhiFu()){
                        zhiFuCount++;
                    }
                    if (jiaItem.isZhiShi()){
                        zhiShiCount++;
                    }
                    break;
                }
            }
            result.add(bean);
        }
        System.out.print(year + "年共开" + list.size() + "期;" + ju + "局"+","+hour+"时");
        System.out.print(",伤门:" + shangMenCount + "次");
        System.out.print(",开门:" + kaiMenCount + "次");
        System.out.print(",值符:" + zhiFuCount + "次");
        System.out.print(",值使:" + zhiShiCount + "次");
        System.out.print(",日干:" + riCount + "次");
        System.out.println(",时干:" + shiCount + "次");

//        System.out.println(year + "年共开" + num + "期;吉时中奖数" + shiCount + "局,中奖率:" + (shiCount * 100 / num) + "%");
        return result;
    }
}
